XEN_SCRIPTS += network-nat vif-nat
XEN_SCRIPTS += block
XEN_SCRIPTS += block-enbd block-nbd
+XEN_SCRIPTS += xen-script-common.sh
XEN_SCRIPTS += xen-hotplug-common.sh xen-network-common.sh vif-common.sh
XEN_SCRIPTS += block-common.sh
#
#============================================================================
+
dir=$(dirname "$0")
+. "$dir/xen-script-common.sh"
. "$dir/xen-network-common.sh"
-# Exit if anything goes wrong.
-set -e
-
-# First arg is the operation.
-OP=$1
-shift
-
-# Pull variables in args in to environment.
-for arg ; do export "${arg}" ; done
+findCommand "$@"
+evalVariables "$@"
vifnum=${vifnum:-0}
bridge=${bridge:-xenbr${vifnum}}
brctl delbr ${bridge}
}
-case ${OP} in
+case "$command" in
start)
op_start
;;
;;
*)
- echo 'Unknown command: ' ${OP} >&2
+ echo "Unknown command: $command" >&2
echo 'Valid commands are: start, stop, status' >&2
exit 1
esac
# XENBUS_PATH path to this device's details in the XenStore (required).
#
# Read from the store:
-# bridge bridge to add the vif to (required).
+# bridge bridge to add the vif to (optional). Defaults to searching for the
+# bridge itself.
# ip list of IP networks for the vif, space-separated (optional).
#
# up:
dir=$(dirname "$0")
. "$dir/vif-common.sh"
-bridge=$(xenstore_read "$XENBUS_PATH/bridge")
+bridge=${bridge:-}
+bridge=$(xenstore_read_default "$XENBUS_PATH/bridge" "$bridge")
+
+if [ -z "$bridge" ]
+then
+ bridge=$(brctl show | cut -d "
+" -f 2 | cut -f 1)
+
+ if [ -z "$bridge" ]
+ then
+ fatal "Could not find bridge, and none was specified"
+ fi
+fi
case "$command" in
up)
handle_iptable
-log debug "vif-bridge operation for $vif successful."
+log debug "Successful vif-bridge operation for $vif, bridge $bridge."
. "$dir/xen-hotplug-common.sh"
. "$dir/xen-network-common.sh"
-command="$1"
+findCommand "$@"
if [ "$command" != "up" ] && [ "$command" != "down" ]
then
fi
+# Parameters may be read from the environment, the command line arguments, and
+# the store, with overriding in that order. The environment is given by the
+# driver, the command line is given by the Xend global configuration, and
+# store details are given by the per-domain or per-device configuration.
+
+evalVariables "$@"
+
+ip=${ip:-}
+ip=$(xenstore_read_default "$XENBUS_PATH/ip" "$ip")
+
+# Check presence of compulsory args.
XENBUS_PATH="${XENBUS_PATH:?}"
vif="${vif:?}"
-ip=$(xenstore-read "$XENBUS_PATH/ip" >&/dev/null || true)
-
function frob_iptable()
{
#
-set -e
+dir=$(dirname "$0")
+. "$dir/xen-script-common.sh"
export PATH="/sbin:/bin:/usr/bin:/usr/sbin:$PATH"
export LANG="POSIX"
exit 1
}
+##
+# xenstore_read <path>+
+#
+# Read each of the given paths, returning each result on a separate line, or
+# exit this script if any of the paths is missing.
+#
xenstore_read() {
local v=$(xenstore-read "$@" || true)
[ "$v" != "" ] || fatal "xenstore-read $@ failed."
echo "$v"
}
+
+##
+# xenstore_read_default <path> <default>
+#
+# Read the given path, returning the value there or the given default if the
+# path is not present.
+#
+xenstore_read_default() {
+ xenstore-read "$1" || echo "$2"
+}
+
+
+##
+# xenstore_write (<path> <value>)+
+#
+# Write each of the key/value pairs to the store, and exit this script if any
+# such writing fails.
+#
xenstore_write() {
log debug "Writing $@ to xenstore."
- xenstore-write "$@" || log err "Writing $@ to xenstore failed."
+ xenstore-write "$@" || fatal "Writing $@ to xenstore failed."
}
log debug "$@" "XENBUS_PATH=$XENBUS_PATH"
--- /dev/null
+#
+# Copyright (c) 2005 XenSource Ltd.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of version 2.1 of the GNU Lesser General Public
+# License as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+
+set -e
+
+
+evalVariables()
+{
+ for arg in "$@"
+ do
+ if expr 'index' "$arg" '=' '>' '1' >/dev/null
+ then
+ eval "$arg"
+ fi
+ done
+}
+
+
+findCommand()
+{
+ for arg in "$@"
+ do
+ if ! expr 'index' "$arg" '=' >/dev/null
+ then
+ command="$arg"
+ return
+ fi
+ done
+}
# The limit (in kilobytes) on the size of the console buffer
#(console-limit 1024)
-## Use the following if VIF traffic is routed.
-# The script used to start/stop networking for xend.
-#(network-script network-route)
-# The default script used to control virtual interfaces.
-#(vif-script vif-route)
-
-## Use the following if VIF traffic is bridged.
-# The script used to start/stop networking for xend.
-(network-script network-bridge)
-# The default bridge that virtual interfaces should be connected to.
-(vif-bridge xenbr0)
-# The default script used to control virtual interfaces.
-(vif-script vif-bridge)
+##
+# To bridge network traffic, like this:
+#
+# dom0: fake eth0 -> vif0.0 -+
+# |
+# bridge -> real eth0 -> the network
+# |
+# domU: fake eth0 -> vifN.0 -+
+#
+# use
+#
+# (network-script network-bridge)
+#
+# Your eth0 is used as the outgoing interface, by default. To use a different
+# one (e.g. eth1) use
+#
+# (network-script 'network-bridge netdev=eth1')
+#
+# The bridge is named xenbr0, by default. To rename the bridge, use
+#
+# (network-script 'network-bridge bridge=<name>')
+#
+# It is possible to use the network-bridge script in more complicated
+# scenarios, such as having two outgoing interfaces, with two bridges, and
+# two fake interfaces per guest domain. To do things like this, write
+# yourself a wrapper script, and call network-bridge from it, as appropriate.
+#
+(network-script network-bridge)
+
+# The script used to control virtual interfaces. This can be overridden on a
+# per-vif basis when creating a domain or a configuring a new vif. The
+# vif-bridge script is designed for use with the network-bridge script, or
+# similar configurations.
+#
+# If you have overridden the bridge name using
+# (network-script 'network-bridge bridge=<name>') then you may wish to do the
+# same here. The bridge name can also be set when creating a domain or
+# configuring a new vif, but a value specified here would act as a default.
+#
+# If you are using only one bridge, the vif-bridge script will discover that,
+# so there is no need to specify it explicitly.
+#
+(vif-script vif-bridge)
+
+
+## Use the following if network traffic is routed, as an alternative to the
+# settings for bridged networking given above.
+#(network-script network-route)
+#(vif-script vif-route)
+
+
+## Use the following if network traffic is routed with NAT, as an alternative
+# to the settings for bridged networking given above.
+#(network-script network-nat)
+#(vif-script vif-nat)
+
# Dom0 will balloon out when needed to free memory for domU.
# dom0-min-mem is the lowest memory level (in MB) dom0 will get down to.